<template>
    <view class="item huodongitem">
        <view class="orderInfo flexb" @click="toLink('showCode')">
            <view :class="{'hd_pic':true,'isFull':isFull || !objInfo.litpic}">
                
                <view class="imgMask" v-if="!isFull && objInfo.litpic"><image mode="aspectFill" class="bottomImg" :src="objInfo.litpic || defaultPro" @error="showDefault()"></image></view>
                <image mode="aspectFill" :src="objInfo.litpic || defaultPro" @error="showDefault()"></image>
                
            </view>   
            <view class="hd_info">
                <view class="h4">{{ objInfo.title }}</view>
                <view class="addr">{{objInfo.addrname && objInfo.addrname.length ? objInfo.addrname[objInfo.addrname.length - 1] : '' }} <text></text> {{ objInfo.address }}</view>
                <view class="date">{{timeTrans(objInfo.began)}} - {{timeTrans(objInfo.end)}}</view>
            </view> 
            <view class="state infoState" v-if="( objInfo.state == '3' || (objInfo.going == 0 && objInfo.price == 0)) || objInfo.state == '4' ">{{ objInfo.state == '4' ? '已退款' : (objInfo.going == 0 || objInfo.going == '0'  ? '已过期' : '已取消')}}</view>
        </view>
        <view class="orderBtn flexb" v-if="(objInfo.price > 0 && objInfo.state != '4') || ((objInfo.state == '1' && objInfo.going) || objInfo.state == '2')">
            <template v-if="objInfo.state == '1' && objInfo.going">
                <view class="btns flexb">
                    <view class="flexb btn showCode" @click="toLink('showCode')">
                        <view class="icon"><image mode="aspectFill" :src="`${imgPath}/code_icon.png?v=${imgVersion}`"></image></view>
                        <text>电子票</text>
                    </view>
                    <view class="flexb btn tuik" v-if="objInfo.sign != 1" @click="toLink('cancel')"><text>{{objInfo.price > 0 ? '申请退票' : '取消报名'}}</text></view>
                </view>
                <view class="flexb right_ticket">
                    <view class="ticket_info">{{objInfo.feetitle && objInfo.price ? objInfo.feetitle : '免费票'}}</view>
                    <view class="ticket_price" v-if="objInfo.price > 0">{{ globalData.appConfig.currency && globalData.appConfig.currency.symbol || '￥'}}<view class="b">{{ (objInfo.price.toString()).split('.')[0] }}<text v-if="(parseInt(objInfo.price).toString()).includes('.')">.{{ parseInt(objInfo.price).toString().split('.')[1] }}</text></view></view>
                </view>
            </template>
            <template v-else-if="objInfo.state == '2'">
                <view class="btns flexb">
                    <view class="flexb btn showCode" @click="toLink('detail')"><text>去评价</text></view>
                </view>
            </template>
            <template v-else>
                <view class="btns flexb" >
                    <view class="btn  flexb tuik" v-if="objInfo.state != '4' && objInfo.sign != 1" @click="toLink('cancel')"><text>退款</text></view>
                </view>
                <view class="state">{{objInfo.going == 0 || objInfo.going == '0'  ? '已过期' : '已取消'}}</view>
            </template>
        </view>
    </view>
</template>

<script>
const app = getApp()
export default {
    props:{
        objInfo:{
            type:Object,
            default:{
                
            }
        },
        ind:{
            type:Number,
            default:0
        }
    },
    computed:{
        // 时间戳转换
        timeTrans(){
                return function(timestr){
                    const dateFormatter = app.dateFormatter(timestr);
                    const year = dateFormatter.year;
                    const month = dateFormatter.month;
                    const day = dateFormatter.day;
                    const hour = dateFormatter.hour;
                    const minute = dateFormatter.minute;
                    const second = dateFormatter.second;
                    
                    let today_dateFormatter = app.dateFormatter(parseInt(new Date().valueOf() / 1000));
                    const today_year = today_dateFormatter.year;
                    const today_month = today_dateFormatter.month;
                    let showStr = '';
                    if(year == today_year){
                        showStr = month + '.' + day + ' ' + hour + ':' + minute ;
                    }else{
                        showStr = year + '.' + month + '.' + day + ' ' + hour + ':' + minute ;
                    }
                    return showStr
                }
            },
    },
    data(){
        return {
            defaultPro:app.globalData.masterDomain + '/static/images/good_default.png',
            globalData:app.globalData,
            platForm:app.globalData.platForm,
            imgPath:app.globalData.imgPath + '/member/order/',
            masterDomain:app.globalData.masterDomain,
            imgVersion:app.globalData.imgVersion,
            isFull:false
        }
    },
    methods:{
        /**
         * 点击按钮 */ 
        toLink(type){
            const that = this;
            if(type == 'detail'){
                // 跳转活动详情
               app.linkTo(that.objInfo.url,false,false)
            }else if(type == 'showCode'){
                // 显示电子票号
                uni.$emit('showwuliu',{objInfo:this.objInfo,ind:this.ind,opt:'hdDetail'})
            }else if(type == 'tuik'){
                // 过期退票
            }else if(type == 'cancel'){
                // 取消报名/申请退款
                uni.$emit('cancelorder',{objInfo:this.objInfo,ind:this.ind})
            }
        },
        showDefault(){
            this.isFull = true
            this.objInfo.litpic = this.defaultPro
        }
    }
}
</script>

<style scoped>
 @import url(./orderlist_huodong.css);
</style>